%%-*- mode: erlang -*-

%% @doc Where LevelDB will store its data.
{mapping, "leveldb.data_root", "eleveldb.data_root", [
  {datatype, directory},
  {default, "$(platform_data_dir)/leveldb"},
  hidden
]}.

%% @doc This parameter defines the percentage of total server memory
%% to assign to LevelDB. LevelDB will dynamically adjust its internal
%% cache sizes to stay within this size.  The memory size can
%% alternately be assigned as a byte count via leveldb.maximum_memory
%% instead.
%% @see leveldb.maximum_memory
{mapping, "leveldb.maximum_memory.percent", "eleveldb.total_leveldb_mem_percent", [
  {default, "70"},
  {datatype, integer}
]}.

%% @doc This parameter defines the number of bytes of server memory to
%% assign to LevelDB. LevelDB will dynamically adjust its internal
%% cache sizes to stay within this size. The memory size can
%% alternately be assigned as percentage of total server memory via
%% leveldb.maximum_memory.percent.
%% @see leveldb.maximum_memory.percent
{mapping, "leveldb.maximum_memory", "eleveldb.total_leveldb_mem", [
  {datatype, bytesize},
  hidden
]}.

%% @doc Whether LevelDB will flush after every write. Note: If you are
%% familiar with fsync, this is analagous to calling fsync after every
%% write.
{mapping, "leveldb.sync_on_write", "eleveldb.sync", [
  {default, off},
  {datatype, flag},
  hidden
]}.

%% @doc limited_developer_mem is a Riak specific option that is used
%% when a developer is testing a high number of vnodes and/or several
%% VMs on a machine with limited physical memory.  Do NOT use this
%% option if making performance measurements.  This option overwrites
%% values given to write_buffer_size_min and write_buffer_size_max.
{mapping, "leveldb.limited_developer_mem", "eleveldb.limited_developer_mem", [
  {default, off},
  {datatype, flag},
  hidden
]}.

%% @doc Each vnode first stores new key/value data in a memory based
%% write buffer. This write buffer is in parallel to the recovery log
%% mentioned in the "sync" parameter. Riak creates each vnode with a
%% randomly sized write buffer for performance reasons. The random
%% size is somewhere between write_buffer_size_min and
%% write_buffer_size_max.
%% @see leveldb.sync
{mapping, "leveldb.write_buffer_size_min", "eleveldb.write_buffer_size_min", [
  {default, "30MB"},
  {datatype, bytesize},
  hidden
]}.

%% @see leveldb.write_buffer_size_min
{mapping, "leveldb.write_buffer_size_max", "eleveldb.write_buffer_size_max", [
  {default, "60MB"},
  {datatype, bytesize},
  hidden
]}.

%% @doc Each database .sst table file can include an optional "bloom
%% filter" that is highly effective in shortcutting data queries that
%% are destined to not find the requested key. The Bloom filter
%% typically increases the size of an .sst table file by about
%% 2%.
{mapping, "leveldb.bloomfilter", "eleveldb.use_bloomfilter", [
  {default, on},
  {datatype, flag},
  hidden
]}.

%% @doc Defines the limit where block cache memory can no longer be
%% released in favor of the page cache.  This has no impact with
%% regard to release in favor of file cache.  The value is per
%% vnode.
{mapping, "leveldb.block_cache_threshold", "eleveldb.block_cache_threshold", [
  {default, "32MB"},
  {datatype, bytesize},
  hidden
]}.

%% @doc Defines the size threshold for a block / chunk of data within
%% one .sst table file. Each new block gets an index entry in the .sst
%% table file's master index.
{mapping, "leveldb.block.size", "eleveldb.sst_block_size", [
  {default, "4KB"},
  {datatype, bytesize},
  hidden
]}.

%% @doc Defines the key count threshold for a new key entry in the key
%% index for a block. Most deployments should leave this parameter
%% alone.
{mapping, "leveldb.block.restart_interval", "eleveldb.block_restart_interval", [
  {default, 16},
  {datatype, integer},
  hidden
]}.


%% @doc Defines the number of incremental adjustments to attempt
%% between the block.size value and the maximum block.size for an .sst
%% table file.  Value of zero disables the underlying dynamic
%% block_size feature.
%% @see leveldb.block.size
{mapping, "leveldb.block.size_steps", "eleveldb.block_size_steps", [
  {default, 16},
  {datatype, integer},
  hidden
]}.

%% @doc Enables or disables the verification of the data fetched from
%% LevelDB against internal checksums.
{mapping, "leveldb.verify_checksums", "eleveldb.verify_checksums", [
  {default, on},
  {datatype, flag},
  hidden
]}.

%% @doc Enables or disables the verification of LevelDB data during
%% compaction.
{mapping, "leveldb.verify_compaction", "eleveldb.verify_compaction", [
  {default, on},
  {datatype, flag},
  hidden
]}.

%% @doc The number of worker threads performing LevelDB operations.
{mapping, "leveldb.threads", "eleveldb.eleveldb_threads", [
  {default, 71},
  {datatype, integer},
  hidden
]}.

%% @doc Option to override LevelDB's use of fadvise(DONTNEED) with
%% fadvise(WILLNEED) instead.  WILLNEED can reduce disk activity on
%% systems where physical memory exceeds the database size.
{mapping, "leveldb.fadvise_willneed", "eleveldb.fadvise_willneed", [
  {default, false},
  {datatype, {enum, [true, false]}},
  hidden
]}.

%% @doc Enables or disables the compression of data on disk.
%% Enabling (default) saves disk space.  Disabling may reduce read
%% latency but increase overall disk activity.  Option can be
%% changed at any time, but will not impact data on disk until
%% next time a file requires compaction.
{mapping, "leveldb.compression", "eleveldb.compression", [
  {default, on},
  {datatype, flag},
  hidden
]}.

%% @doc Controls when a background compaction initiates solely
%% due to the number of delete tombstones within an individual
%% .sst table file.  Value of 'off' disables the feature.
{mapping, "leveldb.compaction.trigger.tombstone_count", "eleveldb.delete_threshold", [
  {default, 1000},
  {datatype, [integer, {atom, off}]},
  hidden
]}.

{translation,
 "eleveldb.delete_threshold",
 fun(Conf) ->
   case cuttlefish:conf_get("leveldb.compaction.trigger.tombstone_count", Conf) of
       off -> 0;
       Int -> Int
   end
 end}.

%% @doc leveldb can be configured to use different mounts for
%% different levels. This tiered option defaults to off, but you can
%% configure it to trigger at levels 1-6. If you do this, anything
%% stored at the chosen level or greater will be stored on
%% leveldb.tiered.mounts.slow, while everything at the levels below will
%% be stored on leveldb.tiered.mounts.fast
%% Levels 3 or 4 are recommended settings.
%% WARNING: There is no dynamic reallocation of leveldb
%% data across mounts.  If you change this setting without manually
%% moving the level files to the correct mounts, leveldb will act in
%% an unexpected state.
%% @see leveldb.tiered.mounts.fast
%% @see leveldb.tiered.mounts.slow
{mapping, "leveldb.tiered", "eleveldb.tiered_slow_level", [
  {default, off},
  {datatype, [
              {atom, off},
              {integer, 1},
              {integer, 2},
              {integer, 3},
              {integer, 4},
              {integer, 5},
              {integer, 6}
             ]},
  hidden
]}.

{translation, "eleveldb.tiered_slow_level",
 fun(Conf) ->
    case cuttlefish:conf_get("leveldb.tiered", Conf) of
        off -> 0;
        I -> I
    end
 end
}.

%% @see leveldb.tiered
{mapping, "leveldb.tiered.path.fast", "eleveldb.tiered_fast_prefix", [
  {datatype, directory},
  hidden
]}.

%% @see leveldb.tiered
{mapping, "leveldb.tiered.path.slow", "eleveldb.tiered_slow_prefix", [
  {datatype, directory},
  hidden
]}.
